<?php
Yii::import('zii.widgets.grid.CGridView');
class GridPlus extends CGridView{
	
	public $template="{searchForm}\n{summary}\n{headerTool}\n{items}\n{pager}";
	public $buttons = array();
	
	public function renderSearchForm(){
		echo '1asdfasfasdfasf';
	}
	
	public function renderHeaderTool()
	{
	    $search = $this->dataProvider->model->attributes;
	    $classAttributes = get_object_vars($this->dataProvider->model);
	    $url = array_merge($search,$classAttributes);
	    
	    //<div class="buttons" style="float:right;">
	    $buttonHtmls = array();
	    foreach ($this->buttons as $button){
	        $tempButton = $button;
	        $tempButton = array(
	            'class' => 'button'
	        );
	        switch ($button['buttonType']){
	            case 'CSV':
	                $tempButton['onClick'] = 'javascript:window.location.href="'.Yii::app()->baseUrl.'/'.$button['url'].'?'.http_build_query($classAttributes).'"';
	                break;
	            case 'Report':
	                $tempButton['onClick'] = 'javascript:window.open("'.Yii::app()->baseUrl.'/'.$button['url'].'?'.http_build_query($classAttributes).'")'; 
	                break;
	            case 'Link':
	                $tempButton['onClick'] = 'javascript:window.location.href="'.Yii::app()->baseUrl.'/'.$button['url'].'"';
	                break;
	        }
	       
        array_push($buttonHtmls, CHtml::button($button['label'],$tempButton));
	    }
	    if (!empty($buttonHtmls)){
	       echo CHtml::tag('div',array('class' => 'buttons' ,'style'=>'float:right'),implode(' ',$buttonHtmls));
	    }
	}
	
}